package subscribersManagement;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class UtilsDate
{
	private static DateFormat f = new SimpleDateFormat("dd/MM/yyyy");
	public static Date stringToDate(String d){
		Date d2 = null;
		try{
			d2=f.parse(d);
		}
		catch(ParseException e)
		{}
		return d2;
		
	}
	public static String dateToString(Date d){
		return f.format(d);
	}
	public static int diff(Date d1, Date d2){
		return (int)((d1.getTime()-d2.getTime())/86400000);//difference in days
	}
	
	public static GregorianCalendar asCalendar(Date date) {
		GregorianCalendar cal = (GregorianCalendar) Calendar.getInstance();
		cal.setTime(date);
		return cal;
	}

}
